package com.kui.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kui.entity.Files;
import com.kui.entity.Folder;
import com.kui.service.FilesService;
import com.kui.service.FolderService;


public class FilesServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String folderid = request.getParameter("foid"); 
		if(folderid == null || "".equals(folderid)){
			response.sendRedirect("folder.jspx");
			return;
		}
		
		
		FolderService fs = new FolderService();
		Folder f = fs.findById(folderid);
		
		if(f == null){
			response.sendRedirect("folder.jspx");
			return;
		}
		
			HttpSession session = request.getSession();
			session.setAttribute("folder", f);
			FilesService fss = new FilesService();
			
			List<Files> filelist = fss.findAllByFolderId(folderid);
			request.setAttribute("filelist", filelist);
			request.getRequestDispatcher("WEB-INF/views/filelist.jsp").forward(request, response);
		
	}

	
	
}
